package com.yys.gulimall.order.vo;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author zq
 * @version 1.0
 * @date 2021/4/3 14:29
 * 订单确认页需要的数据
 */

public class OrderConfirmVo {
    // 收货地址列表
    private List<MemberAddressVo> address;

    // 选中的购物项
    private List<OrderItemVo> orderItemVos;

    // 发票

    // 优惠券

    // 积分
    private Integer integration;

    // 订单总额
//    private BigDecimal total;



    // 应付总额
//    private BigDecimal payPrice;

    // 防重令牌 TODO
    String orderToken;

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }

    public String getOrderToken() {
        return orderToken;
    }

    public Map<Long, Boolean> getStocks() {
        return stocks;
    }

    public void setStocks(Map<Long, Boolean> stocks) {
        this.stocks = stocks;
    }

    Map<Long,Boolean> stocks;


    // 件数
    public Integer getCount() {
        int total = 0;
        for (OrderItemVo orderItemVo : orderItemVos) {
            total += orderItemVo.getCount();
        }
        return total;
    }

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getOrderItemVos() {
        return orderItemVos;
    }

    public void setOrderItemVos(List<OrderItemVo> orderItemVos) {
        this.orderItemVos = orderItemVos;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if(ObjectUtils.isNotEmpty(orderItemVos)){
            for (OrderItemVo orderItemVo : orderItemVos) {
                BigDecimal price = orderItemVo.getPrice().multiply(new BigDecimal(orderItemVo.getCount().toString()));
                total = total.add(price);
            }
        }
        return total;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

}
